//
//  PTStuLSReleaseDetailPeopleInfoCell.m
//  PlanTech
//  发布详情-联系人信息
//  Created by ruifeng song on 2018/7/12.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "PTStuLSReleaseDetailPeopleInfoCell.h"
#import "XHStarRateView.h"

@interface PTStuLSReleaseDetailPeopleInfoCell()

@property(nonatomic,strong)UIImageView * headerImageView ;
@property(nonatomic,strong)UILabel * phoneLabel;
@property(nonatomic,strong)UILabel * nameLabel;
@property(nonatomic,strong)UIView * backView;
@property(nonatomic,strong)XHStarRateView *starRateView;

@property(nonatomic,copy)NSString *phoneNum;

@end

@implementation PTStuLSReleaseDetailPeopleInfoCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        
        _backView = [[UIView alloc]initWithFrame:CGRectMake(12, 10, ScreenWidth -24, 70)];
        _backView.layer.cornerRadius = 6;
        _backView.layer.masksToBounds = YES;
        _backView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_backView];
        
        _headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, (_backView.height - 46)/2, 46, 46)];
        _headerImageView.backgroundColor = [UIColor redColor];
        _headerImageView.layer.cornerRadius = 23;
        _headerImageView.layer.masksToBounds = YES;
        [_backView addSubview:_headerImageView];
        
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(_headerImageView.right + 7,18, 100, 12)];
//        _nameLabel.text = @"张哈哈";
        _nameLabel.font = PTFONT_12;
        _nameLabel.textColor = PTColor_2e2e2e;
        [_backView addSubview:_nameLabel];
        
        CGFloat sizeWidth = [_nameLabel.text widthForFont:_nameLabel.font];
        [_nameLabel setFrame:CGRectMake(_headerImageView.right + 7, 18, sizeWidth, 12)];
        
        _phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(_headerImageView.right + 7,_nameLabel.bottom +13 , 150, 12)];
//        _phoneLabel.text = @"联系电话：18888888888";
        _phoneLabel.font = PTFONT_12;
        _phoneLabel.textColor = PTColor_2e2e2e;
        [_backView addSubview:_phoneLabel];
        
        UIButton * callPhoneButton= [UIButton buttonWithType:UIButtonTypeCustom];
        [callPhoneButton setFrame:CGRectMake(_backView.width - 20 - 30, (_backView.height - 30)/2, 30, 30)];
        [callPhoneButton setImage:[UIImage imageNamed:@"call_phone_img"] forState:UIControlStateNormal];
        [callPhoneButton addTarget:self action:@selector(onClickCallPhoneButton:) forControlEvents:UIControlEventTouchUpInside];
        [_backView addSubview:callPhoneButton];
        
        _starRateView = [[XHStarRateView alloc]initWithFrame:CGRectMake(_nameLabel.right + 7, 18, 58, 10) numberOfStars:5 selectNumberStars:0 rateStyle:WholeStar isAnination:YES isTouch:NO finish:^(CGFloat currentScore) {
            
        }];
        [_backView addSubview:_starRateView];
    }
    return self;
}

-(void)updateMyReleasePartJobPeopleInfoCellWith:(LSDetailReceiverModel *)receiverModel
{
    if (receiverModel == nil) {
        
        return;
    }
    
    if (receiverModel.avatar && receiverModel.avatar.length > 0) {
        
        [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:receiverModel.avatar] placeholderImage:[UIImage imageNamed:@"list_header_default_img"]];
    }
    else
    {
        [self.headerImageView setImage:[UIImage imageNamed:@"list_header_default_img"]];
    }
    
    self.phoneLabel.text = [NSString stringWithFormat:@"联系电话：%@",receiverModel.phone];
    
    self.phoneNum = receiverModel.phone;
    
    self.nameLabel.text = receiverModel.name;
    
    CGFloat starNum = 0;
    
    if (receiverModel.avgRating !=nil) {
        
        starNum = [receiverModel.avgRating floatValue];
    }
    
    [self.starRateView setCurrentScore:starNum];
}

-(void)onClickCallPhoneButton:(id)sender
{
    NSMutableString * string = [[NSMutableString alloc] initWithFormat:@"tel:%@",self.phoneNum];
    
    WISAlertView * alertView = [[WISAlertView alloc]initWithTitle:@"拨打电话" message:string sureBtn:@"确定" cancleBtn:@"取消"];
   
    alertView.resultIndex= ^(NSInteger index) {
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
    };
     [alertView showXLAlertView];

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
